package cst.a330gjq.recyclertest_30gjq;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        // 创建默认的线性 LayoutManager
        layoutManager = new LinearLayoutManager(this);
        // 设置布局管理器
        recyclerView.setLayoutManager(layoutManager);
        // 如果可以确定每个 item 的高度是固定的，设置这个选项可以提高性能
        recyclerView.setHasFixedSize(true);
        // 创建并设置 Adapter     l
        list = getData();
        myAdapter = new MyAdapter(this);
        myAdapter.setList(list);
        recyclerView.setAdapter(myAdapter);
    }
    private List<ArticleBean> getData(){
        List<ArticleBean>list  = new ArrayList<ArticleBean>();
        ArticleBean art;
        art = new ArticleBean();
        art.setArticleId(1);
        art.setTitle("cake");
        art.setImgid(R.drawable.cake );
        art.setTime("2017-4-1 15:16");
        art.setDescription("330gjq");
        list.add(art);

        art = new ArticleBean();
        art.setArticleId(2);
        art.setTitle("beer");
        art.setImgid(R.drawable.beer );
        art.setTime("2017-4-1 15:16");
        art.setDescription("beer");
        list.add(art);

        art = new ArticleBean();
        art.setArticleId(3);
        art.setTitle("carrot");
        art.setImgid(R.drawable.carrot );
        art.setTime("2017-4-1 15:16");
        art.setDescription("carrot");
        list.add(art);

        art = new ArticleBean();
        art.setArticleId(4);
        art.setTitle("chicken");
        art.setImgid(R.drawable.chicken );
        art.setTime("2017-4-1 15:16");
        art.setDescription("chicken");
        list.add(art);

        art = new ArticleBean();
        art.setArticleId(1);
        art.setTitle("pizza");
        art.setImgid(R.drawable.pizza);
        art.setTime("2017-4-1 15:16");
        art.setDescription("pizza");
        list.add(art);

        art = new ArticleBean();
        art.setArticleId(6);
        art.setTitle("fruits");
        art.setImgid(R.drawable.fruits );
        art.setTime("2017-4-1 15:16");
        art.setDescription("fruits");
        list.add(art);
             //写6个
        return list;
        }
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter myAdapter;
    List<ArticleBean> list;

}
